import folium
import webbrowser
from gis.db.DBOperator import DBOperator, ChargingPileInfo

map3 = folium.Map(location=[34.333439,108.705117],
            zoom_start=14,
            tiles='http://wprd01.is.autonavi.com/appmaptile?x={x}&y={y}&z={z}&lang=zh_cn&size=1&scl=1&style=7',
            attr='default'
        )

pt_1 = (34.1833333, 107.633333)
pt_2 = (34.1833333, 109.166666)
pt_3 = (35.5533333, 107.633333)
pt_4 = (35.5533333, 109.166666)

counter = 0

# folium.Polygon(
#     locations=[
#         [34.462745, 108.773165],
#         [34.408945, 108.609829],
#         [34.391948, 108.58468],
#         [34.314002, 108.564854],
#         [34.209867, 108.630085],
#         [34.202201, 108.786898],
#         [34.3103733, 108.814964]
#     ],
#     color='green',
#     fill=True,
#     weight=2
# ).add_to(map3)


# folium.Rectangle([pt_1, pt_2, pt_3, pt_4], color="crimson", fill=False).add_to(map3)

db_operator = DBOperator()
# charging_piles = db_operator.get_charging_piles()
# for charging_pile in charging_piles:
#     #标记一个空心的圈
#     folium.Circle(
#         location=[charging_pile.charging_pile_latitude,charging_pile.charging_pile_longitude],
#         radius=1200,
#         color='crimson',
#         popup='popup',
#         fill=False
#     ).add_to(map3)

# 咸阳秦都站
folium.Circle(
        location=[34.331203,108.666742],
        radius=1000,
        color='orange',
        popup='popup',
        fill=False
    ).add_to(map3)
# 咸阳汽车北站
folium.Circle(
        location=[34.355865,108.692577],
        radius=1000,
        color='orange',
        popup='popup',
        fill=False
    ).add_to(map3)

# 咸阳站
folium.Circle(
        location=[34.344669, 108.734462],
        radius=1000,
        color='orange',
        popup='popup',
        fill=False
    ).add_to(map3)


# 获取家地址
home_locations = db_operator.get_home_location()
for home_location in home_locations:
    folium.Circle(
        location=[home_location.home_latitude, home_location.home_longitude],
        radius=100,
        color='blue',  # 圈的颜色
        popup=home_location.vin,
        fill_color='orange' #填充颜色
    ).add_to(map3)
    counter = counter + 1

# # 获取公司地址
# company_locations = db_operator.get_company_location()
# for company_location in company_locations:
#     folium.Circle(
#         location=[company_location.company_latitude, company_location.company_longitude],
#         radius=100,
#         color='blue',  # 圈的颜色
#         popup=company_location.vin,
#         fill_color='blue'  # 填充颜色
#     ).add_to(map3)
#     counter = counter + 1
#
# # 获取周末地址
# weekend_locations = db_operator.get_weekend_location()
# for weekend_location in weekend_locations:
#     folium.Circle(
#         location=[weekend_location.weekend_latitude, weekend_location.weekend_longitude],
#         radius=100,
#         color='green',  # 圈的颜色
#         popup=weekend_location.vin,
#         fill_color='green'  # 填充颜色
#     ).add_to(map3)
#     counter = counter + 1
#
# # 获取周末地址
# other_locations = db_operator.get_other_location()
# for other_location in other_locations:
#     folium.Circle(
#         location=[other_location.other_latitude, other_location.other_longitude],
#         radius=100,
#         color='orange',  # 圈的颜色
#         popup=other_location.vin,
#         fill_color='orange'  # 填充颜色
#     ).add_to(map3)
#     counter = counter + 1

#108.600621,34.295181

map3.save('f1.html')
webbrowser.open('f1.html')
print(counter)